package com.kaifamiao.handler;

import com.kaifamiao.entity.User;
import org.apache.commons.dbutils.ResultSetHandler;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author lucien-ma
 * @date 2021/10/12
 * @apiNote
 */
public class UserResultSetHandler implements ResultSetHandler<User> {
    @Override
    public User handle(ResultSet rs) throws SQLException {
        if (rs.next()) {
            User user = new User();
            user.setId(rs.getInt("id"));
            user.setUsername(rs.getString("username"));
            user.setPassword(rs.getString("password"));
            return user;
        }
        return null;
    }
}
